<?php
/**
 * 
 * Modelo de script
 * @author natanael
 * 
 */
class Mscript extends Model{
    
	private $_nameTable = "SCT_Script";
	
    public function __construct()
    {
        parent::Model();
	    $this->load->database();
    }
    
    public function loadScript($start = false, $offset = false, $sortname = false, $sortorder = false)
    {
            
           if($offset != false)
		       $this->db->limit($offset, $start);

		   if($sortname != false && $sortorder != false) 
			    $this->db->order_by($sortname, $sortorder);
				  
		    $result = $this->db->get_where($this->_nameTable);
	
			return $this->GetArrayFromQueryResult($result);
			
     }
     
     public function loadScriptHistorico($start = false, $offset = false, $sortname = false, $sortorder = false)
     {
            if($offset != false)
		       $this->db->limit($offset, $start);

		   if($sortname != false && $sortorder != false) 
			    $this->db->order_by($sortname, $sortorder);
				  
		    $result = $this->db->get_where("SCT_ScriptHistorico");
	
			return $this->GetArrayFromQueryResultHistorico($result);
     
     }
     
     private function GetArrayFromQueryResultHistorico($result)
      {
           if ($result->num_rows() == 0)
				      return false;
	
			 $data_arr = array();
	
			foreach ($result->result() as $record) {
				$data_arr[] = new SCT_ScriptHistorico($record);
		    }
	
			return $data_arr;
      }
       
     public function loadRegistroByWhere($where)
     {
            $result = $this->db->get_where($this->_nameTable, $where);
            return $this->GetArrayFromQueryResult($result);
     }
       
     public function LoadRegistroById($id) 
	 {
		   $qresult = $this->db->get_where($this->_nameTable, array('idScript' => $id));		
		
		   if ($qresult->num_rows() == 0)
		   {
			 return false;
		   }	
           
		   return new SCT_Script($qresult->row());
	  }
       
      private function GetArrayFromQueryResult($result)
      {
           if ($result->num_rows() == 0)
				      return false;
	
			 $data_arr = array();
	
			foreach ($result->result() as $record) {
				$data_arr[] = new SCT_Script($record);
		    }
	
			return $data_arr;
      }
       
      public function addRegistro($data)
      {
          if ($this->db->insert($this->_nameTable,$data)) 
             return true;
             
            return false;   
         
      }
       
      public function updateRegistro($data, $where)
      {
          if ($this->db->update($this->_nameTable,$data, $where))
             return true;

             return false; 
      
      }
       
      public function daleteRegistro($where)
      {
           if($this->db->delete($this->_nameTable, $where))
              return true;
              
             return false;      
      }

}

class SCT_Script{
      
      private $_idScript = 0;
      private $_titleScript = "";
      private $_subjectScript = "";
      private $_fromScript = 0;
      private $_tipoScript = 0;
      private $_bodyScript = "";
      private $_departamentoScript = 0;
      private $_categoriaScript = 0;
      
      public function __construct($ojt)
      {
         $this->setIdScripst($ojt->idScript);
         $this->setTitleScript($ojt->titleScript);
         $this->setSubjectScript($ojt->subjectScript);
         $this->setFromScript($ojt->fromScript);
         $this->setTipoScript($ojt->tipoScript);
         $this->setBodyScript($ojt->bodyScript);
         $this->setDepartamentoScript($ojt->departamenoScript);
         $this->setCategoriaScript($ojt->categoriaScript);

      }
      
      public function getIdScripst()
      {
        return $this->_idScript;
      }
      
      public function setIdScripst($ojt)
      {
        $this->_idScript = $ojt;
      }
      
      public function getTitleScript()
      {
        return $this->_titleScript;
      }
      
      public function setTitleScript($ojt)
      {
        $this->_titleScript = $ojt;
      }
      
      public function getSubjectScript()
      {
        return $this->_subjectScript;
      }
      
      public function setSubjectScript($ojt)
      {
        $this->_subjectScript = $ojt;
      } 
      
      public function getFromScript()
      {
        return $this->_fromScript;
      }
      
      public function setFromScript($ojt)
      {
        $this->_fromScript = $ojt;
      } 
      
      public function getTipoScript()
      {
        return $this->_tipoScript;
      }
      
      public function setTipoScript($ojt)
      {
        $this->_tipoScript = $ojt;
      } 
      
      public function getBodyScript()
      {
        return $this->_bodyScript;
      }
      
      public function setBodyScript($ojt)
      {
        $this->_bodyScript = $ojt;
      } 
      
      public function getDepartamentoScript()
      {
        return $this->_departamentoScript;
      }
      
      public function setDepartamentoScript($ojt)
      {
        $this->_departamentoScript = $ojt;
      }

      public function getCategoriaScript()
      {
        return $this->_categoriaScript;
      }
      
      public function setCategoriaScript($ojt)
      {
        $this->_categoriaScript = $ojt;
      }
      
}


class SCT_ScriptHistorico{

      private $_idScript = 0;
      private $_titulo = "";
      private $_subTitulo = "";
      private $_idFrom = 0;
      private $_tipo = 0;
      private $_idDepartamento = 0;
      private $_idCategoria = 0;
      private $_body = "";
      private $_fecha = "";
      
      public function __construct($ojt)
      {
            $this->setIdScript($ojt->Id_Script);
            $this->setTitulo($ojt->titulo);
            $this->setSubTitulo($ojt->subTitulo);
            $this->setIdFrom($ojt->Id_From);
            $this->setTipo($ojt->tipo);
            $this->setIdDepartamento($ojt->Id_Departamento);
            $this->setIdCategoria($ojt->Id_Categoria);
            $this->setBody($ojt->bodyScript);
            $this->setFecha($ojt->fecha);
      
      }
      
      public function getIdScript()
      {
         return $this->_idScript;
      }
      
      public function setIdScript($ojt)
      {
          $this->_idScript = $ojt;
      }
      
      public function getTitulo()
      {
         return $this->_titulo;
      }
      
      public function setTitulo($ojt)
      {
          $this->_titulo = $ojt;
      }
      
      public function getSubTitulo()
      {
         return $this->_subTitulo;
      }
      
      public function setSubTitulo($ojt)
      {
          $this->_subTitulo = $ojt;
      }

      public function getIdFrom()
      {
         return $this->_idFrom;
      }
      
      public function setIdFrom($ojt)
      {
          $this->_idFrom = $ojt;
      }

      public function getTipo()
      {
         return $this->_tipo;
      }
      
      public function setTipo($ojt)
      {
          $this->_tipo = $ojt;
      }

      public function getIdDepartamento()
      {
         return $this->_idDepartamento;
      }
      
      public function setIdDepartamento($ojt)
      {
          $this->_idDepartamento = $ojt;
      }

      public function getIdCategoria()
      {
         return $this->_idCategoria;
      }
      
      public function setIdCategoria($ojt)
      {
          $this->_idCategoria = $ojt;
      }

      public function getBody()
      {
         return $this->_body;
      }
      
      public function setBody($ojt)
      {
          $this->_body = $ojt;
      }
      
      public function getFecha()
      {
         return $this->_fecha;
      }
      
      public function setFecha($ojt)
      {
          $this->_fecha = $ojt;
      }
}
